//货柜与商品-商品列表
App.util.ns('Admin.Goods.Goods');
App.pages.add((function(){
    var NS = Admin.Goods.Goods;
    var page = new App.Page({
        name: 'goods/goods/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        //面包屑导航
        this.setBreadcrumb([{
            icon: '<i class="fa fa-crosshairs"></i>',
            content: '商品管理'
        }, {
            content: '商品列表'
        }]);
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/goods/goods',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                //showId: false,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'timeRange'},
                {type: 'select', name: 'is_experience', title: '可否体验', width: '90px', items: [
                    [0, '可体验'],
                    [1, '不可体验']
                ]},
                {type: 'select', name: 'status', title: '状态', width: '90px', items: [
                    [0, '下线'],
                    [1, '在线']
                ]}
            ],
            menu: [
                {parent: 'add', permission: 'op:admin.goods.goods.create'},
                {type: 'globe', name: '导出', permission: 'op:admin.goods.goods', operation:function (dataTable) {
                    //发请求ajax
                    $.ajax({
                        url: 'admin/goods/goods/multiExport',
                        data: dataTable.filter.data,
                        type: "get",
                        async: false,
                        success: function (returnData) {
                            returnData = JSON.parse(returnData)
                            if(returnData.status == '0'){
                                var $a = $("<a>");
                                $a.attr("href", returnData.data.file);
                                $a.attr("download", returnData.data.filename);
                                $("body").append($a);
                                $a[0].click();
                                $a.remove();
                            }else {
                                App.util.hint.toast({
                                    type: 'error',
                                    text: returnData.msg
                                }).delay(500);
                            }

                        },
                        error: function () {
                            App.util.hint.toast({
                                type: 'error',
                                text: '格式不对'
                            }).delay(500);
                        }
                    });

                }},
                {parent: 'view', permission: 'op:admin.goods.goods.detail'},
                {parent: 'edit', permission: 'op:admin.goods.goods.update'},
                {type: 'inline', permission: 'op:admin.goods.goods.online',
                    name: '上线', operation: {type: 'change', url: 'online'},
                    conditions: [['status', '0']]
                },
                {type: 'inline', permission: 'op:admin.goods.goods.offline',
                    name: '下线', operation: {type: 'change', url: 'offline'},
                    conditions: [['status', '1']]
                },
                {type: 'multi', name: '状态', openable: true, items: [
                    {type: 'multi', permission: 'op:admin.goods.goods.multiOnline', name: '上线', operation: {type: 'change', url: 'multiOnline', confirm: true}},
                    {type: 'multi', permission: 'op:admin.goods.goods.multiOffline', name: '下线', operation: {type: 'change', url: 'multiOffline', confirm: true}}
                    ], permission:[
                        'op:admin.goods.goods.multiOnline',
                        'op:admin.goods.goods.multiOffline'
                ]},
                {parent: 'drop', permission: 'op:admin.goods.goods.delete'},
                {parent: 'multiDrop', permission: 'op:admin.goods.goods.multiDelete'},
                {parent: 'oplog', permission: 'op:admin.goods.goods.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            },
            dragSort:{
                permission: 'op:admin.goods.goods.sort',
                url:'sort',
                filed:'sort',
                conditions:[['status', '1']]
            },
        }, page);
        this.dataTable.fix(this.contentContainer);
        this.dataTable.loadData();
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());